$(function () {
    /* 表单校验 */
    let form = layui.form
    form.verify({
        Pwd: [/^[\S]{6,12}$/, '密码的必须是6-12位的非空字符'],

        newPwd: function (value) {
            let v1 = $('[name=oldPwd]').val()
            /* console.log(v1); */
            if (value == v1) {
                return '新旧密码不能相同'
            }
        },

        rePwd: function (value) {
            let v2 = $('[name=newPwd]').val()
            /* console.log(v2); */
            if (value != v2) {
                return '两次新密码不一致！'
            }
        }
    })
 
    $('form').on('submit',function(e){
        e.preventDefault()
        axios({
            method:'POST',
            url:'/my/updatepwd',
            data:$(this).serialize()
        }).then(({data:res})=>{
            if(res.status!==0){
                return layui.layer.msg(res.message)
            }
            layui.layer.msg('恭喜您,修改成功')
            /* 重置 */
            $('form')[0].reset()

            setTimeout(function(){
                window.parent.location.href='/login.html'
            },1500)
        })
    })
    

})